# 修改后的model.py.j2模板
from sqlalchemy import {{ sa_imports|join(', ') }}
from sqlalchemy.orm import Mapped, mapped_column
from src.core.base.orm.orm import AbstractORMModel
{% if need_datetime -%}
from datetime import datetime
{% endif -%}
{% if need_func -%}
from sqlalchemy import func
{% endif -%}


class {{ model_name }}(AbstractORMModel):
    __tablename__ = "{{ table_name }}"
    __table_args__ = {"comment": "{{ comment }}"}

    {% for field in fields %}
    {{ field.name }}: Mapped[{{ field.py_type_anno }}] = mapped_column(
        {{ field.sa_type }}{% if field.sa_args %}{{ field.sa_args }}{% endif %}{% if field.is_key %},
        primary_key=True{% endif %}{% if field.nullable is not none %},
        nullable={{ field.nullable }}{% endif %}{% if field.description %},
        comment="{{ field.description }}"{% endif %}{% if field.server_default %},
        server_default={{ field.server_default }}{% endif %}{% if field.sort_order is not none %},
        sort_order={{ field.sort_order }}{% endif %}{% if field.default_value is not none %},
        default={{ field.default_value }}{% endif %}
    )
    {% endfor %}